<script setup>
    import {ref, computed, watch} from "vue"
    // 监视器练习
    const km = ref("")
    const m = ref("")
    const text = ref("")
    watch(
      km, (newVal, oldVal) => {
        text.value = `修改前：${oldVal}，修改后：${newVal}`
        km.value = newVal
        m.value = newVal * 1000
      }
    )
    watch(
      m, (newVal, oldVal) => {
        m.value = newVal,
        km.value = newVal / 1000
      }
    )

</script>

<template>
  <div>
    <span>
      千米：<input type="number" v-model="km">
    </span>
    <span>
      米：<input type="number" v-model="m">
    </span>
    <p>{{ text }}</p>
  </div>
</template>

<style scoped>

</style>